package cn.webestar.scms.user.api.dto.Role;

import cn.webestar.scms.commons.api.SimpleBody;
import cn.webestar.scms.user.entity.Role;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.Set;

@Data
@Schema(description = "RoleSimpleDTO")
public class RoleSimpleDTO extends SimpleBody {

    @Schema(description = "cid")
    private Long cid;

    @Schema(description = "名称")
    private String name;

    @Schema(description = "备注")
    private String remark;

    @Schema(description = "权限资源")
    private Set<Long> resourceIds;

    @Schema(description = "创建人")
    private Long creator;

    @Schema(description = "更新人")
    private Long updater;

    @Schema(description = "创建时间")
    private Date createTime;

    @Schema(description = "更新时间")
    private Date updateTime;

    @Schema(description = "是否可用")
    private Boolean isEnable;

    @Override
    public LambdaQueryWrapper<Role> toQueryWapper() {
        LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
        if (cid!=null) {
            queryWrapper.eq(Role::getCid, cid);
        }
        if (StringUtils.hasText(name)) {
            queryWrapper.eq(Role::getName, name);
        }
        if (StringUtils.hasText(remark)) {
            queryWrapper.eq(Role::getRemark, remark);
        }
        if (resourceIds!=null) {
            queryWrapper.eq(Role::getResourceIds, resourceIds);
        }
        if (creator!=null) {
            queryWrapper.eq(Role::getCreator, creator);
        }
        if (updater!=null) {
            queryWrapper.eq(Role::getUpdater, updater);
        }
        if (createTime!=null) {
            queryWrapper.eq(Role::getCreateTime, createTime);
        }
        if (updateTime!=null) {
            queryWrapper.eq(Role::getUpdateTime, updateTime);
        }
        if (isEnable!=null) {
            queryWrapper.eq(Role::getIsEnable, isEnable);
        }
        return queryWrapper;
    }

}
